package nowcoder;

import java.io.*;
import java.util.*;

public class C_68 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static final int N = 5010;
    static int t;
    static int[][] cnt = new int[N][30];
    static int[][] c = new int[N][N];
    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void _solve() throws IOException {

    }

    public static void main(String[] args) throws IOException {
//        t = Integer.parseInt(bin.readLine());
        t = cin();
        while (t -- > 0) {
//            _solve();
            int n = cin();
//        int[][] c = new int[N][N];
            in.nextToken();
            char[] s = in.sval.toCharArray();
//        for (int i = 0; i < N; i ++ ) Arrays.fill(cnt[i], 0);
            for (int i = 0; i <= n + 5; i ++ ) {
                for (int j = 0; j <= n + 5; j ++ ) c[i][j] = 0;
                for (int j = 0; j <=26; j ++ ) cnt[i][j] = 0;
            }
            for (int i = 1; i <= n; i ++ ) {
                for (int j = 0; j < 26; j ++ ) {
                    char ss = s[i - 1];
                    cnt[i][j] = cnt[i - 1][j];
                    if (ss == 'a' + j) cnt[i][j] ++ ;
                }
            }

            double res = 0;
            for (int l = 1; l <= n; l ++ ) {
                for (int r = l; r <= n; r ++ ){
                    if (l == r) c[l][r] = 0;
                    else c[l][r] = c[l][r - 1] + (cnt[r - 1][s[r - 1] - 'a'] - cnt[l - 1][s[r - 1] - 'a']);
                    res = Math.max(c[l][r] / (r - l + 1.0), res);
                }
            }
//        out.printf("%.6f\n", res);
            System.out.printf("%.6f\n", res);
        }
//        out.flush();
    }
}
